var http=require("http");
var fs=require("fs");
var path=require("path");
var content;
var filePath=path.join(__dirname,"/"+process.argv[2]);
if(process.argv[2]){
    fs.access(filePath,(err)=>{
        // filePath=path.join(__dirname,"/fileReader1.js");
        console.log(err);
    });
}else{
    filePath=path.join(__dirname,"/fileReader1.js");
}


show=()=>{
    http.createServer((req,res)=>{
        res.writeHead(200,{"Content-Type":"text/html"});
        res.write("<!DOCTYPE html><html>"+
        "<head></head><body style='background:white'>"+
            
        "<div>"+content+"</div>"
            
            +"</body></html>"    );
        res.end;
    }).listen(8081);
}

fs.readFile(filePath,(err,data)=>{
    content=data.toString('utf8');
    if(err){
        console.log(err)
    }else{
        show();       
        
    }
})

console.log("server is listening 8081");